package org.aplombh.java.awcing.basic.struct.stack;

public class MyStack {

    private static final int N = 100010;

    private int[] stack;
    private int tail;

    public MyStack() {
        init();
    }

    public void init() {
        if (stack == null)
            stack = new int[N];
        // 如果tail>0,则栈不为空,初始为空
        tail = -1;
    }

    // 压入栈中
    public void push(int x) {
        stack[++tail] = x;
    }

    // 弹出栈
    public int pop() {
        return stack[tail--];
    }

    // 查询
    public int query() {
        return stack[tail];
    }

    // tail＜0则为空
    public String empty() {
        return tail < 0 ? "YES" : "NO";
    }

}
